home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / libconv / EXAMPLES / fex3.f < prev    next >
Encoding:
Text File  |  1994-08-02  |  3.3 KB  |  70 lines

  1.       Program ex3
  2. ******************************************************************************
  3. *                                                                            *
  4. *  This program is to illustrate the use of 2D and Multiple 1D filters       *
  5. *  We use here DFIR2D and DFIRM1D modules from LIBCONV                       *
  6. *                                                                            *
  7. ******************************************************************************
  8. *                                                                            *
  9. *  The 1D filter in the X direction will be (1/2,-1.,1/2)                    *
  10. *                               --- Approximation of second derivative       *
  11. *  In the Y direction the 1D filter will be (-1/2,0.,1/2)                    *
  12. *                               --- Approximation of first  derivative       *
  13. *  The equivalent 2D filter will be:                                         *
  14. *                               -1/4   0   +1/4                              *
  15. *                               +1/2   0   -1/2                              *
  16. *                               -1/4   0   +1/4                              *
  17. *                               ------ Y ----->                              *
  18. *  This is the approximation of the triple derivative D()/Dxxy               *
  19. *                                                                            *
  20. ******************************************************************************
  21.       parameter (HX=5, HY=5, NX=(2*HX+1), NY=(2*HY+1))
  22.       parameter (PI = 3.14159265358979323846)
  23.       double precision input(-HX:HX,-HY:HY), fil2d(-1:1,-1:1)
  24.       double precision filx(-1:1), fily(-1:1), temp(-HX:HX,-HY:HY)
  25.       double precision out1(-HX:HX,-HY:HY), out2(-HX:HX,-HY:HY)
  26.       double precision scale_x, scale_y
  27.       data fil2d/-.25,0.5,-.25,0.0,0.0,0.0,.25,-.5,.25/
  28.       data filx /0.5,-1.,0.5/,        fily/-.5,0.0,0.5/
  29. * Init Input
  30.       scale_x = PI/dfloat(HX)
  31.       scale_y = PI/dfloat(HY)
  32.       do j = -HY,HY
  33.         do i = -HX,HX
  34.           input(i,j) = cos(i*scale_x)*(1.-dfloat(ABS(i))/dfloat(HX))
  35.      $               * cos(j*scale_y)*(1.-dfloat(ABS(j))/dfloat(HY))
  36.         end do
  37.       end do
  38.  
  39. *  2D FIR filter:
  40.       call dfir2d( input,1,NX,-HX,NX,-HY,NY,
  41.      $             fil2d,1,3, -1,  3, -1, 3,
  42.      $             out1, 1,NX,-HX,NX,-HY,NY, 1.0d0, 0.0d0)
  43.  
  44. *  Multiple 1D FIR filter in the X direction:
  45.       call dfirm1d( input,1,NX,-HX,NX, NY,
  46.      $              filx, 1,   -1, 3,
  47.      $              temp, 1,NX,-HX,NX,       1.0d0, 0.0d0)
  48.  
  49. *  Multiple 1D FIR filter in the Y direction:
  50.       call dfirm1d( temp,NX,1,-HY,NY, NX,
  51.      $              fily, 1,   -1, 3,
  52.      $              out2,NX,1,-HY,NY,        1.0d0, 0.0d0)
  53.  
  54. *  Print out the input and the two results
  55.       write(6,11)
  56.       write(6,12) ((input(i,j), j=-HY,HY), i=-HX,HX)
  57.       write(6,13)
  58.       write(6,12) ((out1(i,j), j=-HY,HY), i=-HX,HX)
  59.       write(6,14)
  60.       write(6,12) ((temp(i,j), j=-HY,HY), i=-HX,HX)
  61.       write(6,15)
  62.       write(6,12) ((out2(i,j), j=-HY,HY), i=-HX,HX)
  63.  11   format('Input : ')
  64.  12   format(11f7.3)
  65.  13   format(/'After application of 2D FIR filter:')
  66.  14   format(/'After multiple 1D FIR filters in the X Direction:')
  67.  15   format(/'After final multiple 1D FIR filters in the Y Direction:')
  68.       stop
  69.       end
  70.